﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x02000399 RID: 921
public class ColorChangeButton : MonoBehaviour
{
	// Token: 0x060016C6 RID: 5830 RVA: 0x000991C8 File Offset: 0x000973C8
	private void Start()
	{
	}

	// Token: 0x060016C7 RID: 5831 RVA: 0x000991CC File Offset: 0x000973CC
	public void Setup(string title, Color color, bool hasAlpha, Action<Color> onChangeAct)
	{
		this.title.text = title;
		this.hasAlpha = hasAlpha;
		this.onChangeAct = onChangeAct;
		this.color = color;
		this.alphaBack.gameObject.SetActive(hasAlpha);
		this.SetImageColor();
	}

	// Token: 0x060016C8 RID: 5832 RVA: 0x00099208 File Offset: 0x00097408
	private void Update()
	{
	}

	// Token: 0x060016C9 RID: 5833 RVA: 0x0009920C File Offset: 0x0009740C
	private void OnDisable()
	{
		if (this.colorUI != null && this.colorUI.openUI == this)
		{
			this.colorUI.Close();
		}
	}

	// Token: 0x060016CA RID: 5834 RVA: 0x00099240 File Offset: 0x00097440
	public void SetTitle(string title)
	{
		this.title.text = title;
	}

	// Token: 0x060016CB RID: 5835 RVA: 0x00099250 File Offset: 0x00097450
	public void SetColor(Color color)
	{
		this.color = color;
		this.SetImageColor();
	}

	// Token: 0x060016CC RID: 5836 RVA: 0x00099260 File Offset: 0x00097460
	private void OnChangeColor(Color color)
	{
		this.color = color;
		this.SetImageColor();
		if (this.onChangeAct != null)
		{
			this.onChangeAct(color);
		}
	}

	// Token: 0x060016CD RID: 5837 RVA: 0x00099288 File Offset: 0x00097488
	private void SetImageColor()
	{
		Color color = this.color;
		color.a = 1f;
		this.colorPreview.color = color;
		float fillAmount = (!this.hasAlpha) ? 0f : this.color.a;
		this.alphaPreview.fillAmount = fillAmount;
	}

	// Token: 0x060016CE RID: 5838 RVA: 0x000992E4 File Offset: 0x000974E4
	public void OpenColorUI()
	{
		this.colorUI.Open(this, this.title.text, this.color, this.hasAlpha, new Action<Color>(this.OnChangeColor));
	}

	// Token: 0x060016CF RID: 5839 RVA: 0x00099318 File Offset: 0x00097518
	public EventTrigger GetEventTrigger()
	{
		EventTrigger component = base.GetComponent<EventTrigger>();
		if (component)
		{
			return component;
		}
		return base.gameObject.AddComponent<EventTrigger>();
	}

	// Token: 0x060016D0 RID: 5840 RVA: 0x00099344 File Offset: 0x00097544
	private void SetColorUIPos()
	{
		RectTransform rectTransform = base.transform as RectTransform;
		RectTransform trans = this.colorUI.transform as RectTransform;
		Canvas componentInParent = rectTransform.GetComponentInParent<Canvas>();
		Vector3[] array = new Vector3[4];
		rectTransform.GetWorldCorners(array);
		float num = 1f / componentInParent.scaleFactor;
		float num2 = (float)Screen.width * num;
		float num3 = (float)Screen.height * num;
		float num4 = array[0].x * num;
		float num5 = array[0].y * num;
		float num6 = num4;
		float num7 = num4 + rectTransform.sizeDelta.x;
		float y = num5 + rectTransform.sizeDelta.y;
		float num8 = 10f;
		float num9 = num7;
		Vector2 offsetPivot = new Vector2(0f, 1f);
		if (num7 > num2 * 0.5f && num6 > num2 * 0.5f)
		{
			num9 = num6;
			num9 -= num8;
			offsetPivot.x = 1f;
		}
		else
		{
			num9 += num8;
		}
		Vector2 pos = new Vector2(num9, y);
		this.SetPosUI(trans, pos, offsetPivot);
	}

	// Token: 0x060016D1 RID: 5841 RVA: 0x0009946C File Offset: 0x0009766C
	private void SetPosUI(RectTransform trans, Vector2 pos, Vector2 offsetPivot)
	{
		Canvas componentInParent = trans.GetComponentInParent<Canvas>();
		float num = (float)Screen.width * (1f / componentInParent.scaleFactor);
		float num2 = (float)Screen.height * (1f / componentInParent.scaleFactor);
		float num3 = trans.anchorMin.x * num;
		float num4 = trans.anchorMin.y * num2;
		Vector2 a = new Vector2(-num3, -num4);
		Vector2 b = new Vector2(trans.sizeDelta.x * trans.pivot.x, trans.sizeDelta.y * trans.pivot.y);
		Vector2 b2 = new Vector2(trans.sizeDelta.x * -offsetPivot.x, trans.sizeDelta.y * -offsetPivot.y);
		trans.anchoredPosition = a + b + pos + b2;
		float num5 = num3 + trans.offsetMin.x;
		float num6 = num3 + trans.offsetMax.x;
		float num7 = num4 + trans.offsetMax.y;
		float num8 = num4 + trans.offsetMin.y;
		if (num5 < 0f)
		{
			trans.anchoredPosition += new Vector2(-num5, 0f);
		}
		if (num6 > num)
		{
			trans.anchoredPosition += new Vector2(num - num6, 0f);
		}
		if (num7 > num2)
		{
			trans.anchoredPosition += new Vector2(0f, num2 - num7);
		}
		if (num8 < 0f)
		{
			trans.anchoredPosition += new Vector2(0f, -num8);
		}
	}

	// Token: 0x04001A8D RID: 6797
	private Color color;

	// Token: 0x04001A8E RID: 6798
	[SerializeField]
	private Text title;

	// Token: 0x04001A8F RID: 6799
	public MoveableColorCustomUI colorUI;

	// Token: 0x04001A90 RID: 6800
	[SerializeField]
	private Image colorPreview;

	// Token: 0x04001A91 RID: 6801
	[SerializeField]
	private Image alphaBack;

	// Token: 0x04001A92 RID: 6802
	[SerializeField]
	private Image alphaPreview;

	// Token: 0x04001A93 RID: 6803
	[SerializeField]
	private bool hasAlpha;

	// Token: 0x04001A94 RID: 6804
	private Action<Color> onChangeAct;
}
